package com.xysq.util;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author 黄东凯
 */
public class PropertiesUtil {
    //H5地址
    private static final String H5_ADDRESS = "server.h5";
    //券控api地址
    private static final String QKAPI_ADDRESS = "server.qkapi";
    //校有api地址
    private static final String XYAPI_ADDRESS = "server.xyapi";
    // 环境配置文件
    private static final String ENVIRONMENT_PROPERTIES = "environment.properties";
    // 应用配置文件
    private static final String APP_PROPERTIES = "app.properties";
    // 环境配置文件的key
    private static final String SERVER_IP = "server.ip";
    private static final String SERVER_IMAGE = "server.image";
    // 应用配置文件的key
    private static final String APP_KEY = "app.key";
    private static final String APP_APPID = "app.appId";
    private static final String APP_MCHID = "app.mchid";
    private static final String APP_SECRET = "app.mchIdSecret";
    private static Properties enviromentProperties;
    private static Properties appProperties;
    private static final String SERVER_ALIPAY_NOTIFY = "server.alipay.notify";
    // 订单支付回调地址后缀
    private static final String ALIPAY_NOTIFY_SUFFIX = "/payment/alipay/notifySecureMsg.a";
    // 充值支付回调地址后缀
    private static final String ALIPAY_NOTIFY_RECHARGE_SUFFIX = "/payment/alipay/notifyRechargeSecureMsg.a";

    public static void init(Context context) {
        try {
            enviromentProperties = new Properties();
            InputStream inputStream = context.getAssets().open(ENVIRONMENT_PROPERTIES);
            enviromentProperties.load(inputStream);
            appProperties = new Properties();
            inputStream = context.getAssets().open(APP_PROPERTIES);
            appProperties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //*-----------环境配置---------------*//
    public static String getServerIp() {
        return enviromentProperties.get(SERVER_IP).toString();
    }

    public static String getImageServer() {
        return enviromentProperties.get(SERVER_IMAGE).toString();
    }

    public static String getH5Address() {
        return enviromentProperties.get(H5_ADDRESS).toString();
    }

    public static String getQkapiAddress() {
        return enviromentProperties.get(QKAPI_ADDRESS).toString();
    }

    public static String getXyapiAddress() {
        return enviromentProperties.get(XYAPI_ADDRESS).toString();
    }

    //*-----------环境配置---------------*//

    //*-----------应用配置---------------*//
    public static String getAppKey() {
        return appProperties.get(APP_KEY).toString();
    }
    public static String getAppWechatKey() {
        return appProperties.get(APP_APPID).toString();
    }
    public static String getMchid() {
        return appProperties.get(APP_MCHID).toString();
    }
    public static String getAppSecret() {
        return appProperties.get(APP_SECRET).toString();
    }

    public static String getAlipayNotifyUrl() {
        return enviromentProperties.get(SERVER_ALIPAY_NOTIFY).toString() + ALIPAY_NOTIFY_SUFFIX;
    }

    public static String getAlipayNotifyRechargeUrl() {
        return enviromentProperties.get(SERVER_ALIPAY_NOTIFY).toString() + ALIPAY_NOTIFY_RECHARGE_SUFFIX;
    }
}
